﻿Namespace Emeklilik.Yoklama
	Module Functions

		Function AdresListesi(ByVal Process As Token, ByVal Kimlik As String) As Recordset
			Q("select rtrim(adi)+' '+rtrim(soyadi) as adi, adr, adrsemt")
			Q("from yaslılık..yasmaasbil where odeyerkod = 0")
			If Kimlik <> "" Then Q("and a.kimlik = '" & Kimlik & "'")
			Q(" order by 1")
			Return Process.OpenSQL("*")
		End Function

		Function CekDagilimi(ByVal Process As Token, ByVal Bolge As String, ByVal Kimlik As String) As Recordset
			Q("select a.hturu,a.kararno,a.kimlik,rtrim(b.adi)+' '+rtrim(b.soyadi) as adi,a.cekno,d.bolge")
			Q("from yaslılık..yasmaas a inner join yaslılık..yasmaasbil b on a.hturu = b.hturu and a.kararno = b.kararno and a.kimlik = b.kimlik and a.yil = 2009 and a.ay = 4")
			Q("inner join yaslılık..yoklama2008 c on a.hturu = c.hturu and a.kararno = c.kararno and a.kimlik = c.kimlik")
			Q("left join yaslılık..odemeyeri d on c.odeyerkod = d.odeyerkod")
			Q("where a.odeyerkod = 0")
			If Bolge <> "" Then Q("and d.bolge = '" & Bolge & "'")
			If Kimlik <> "" Then Q("and a.kimlik = '" & Kimlik & "'")
			Q(" order by cekno")
			Return Process.OpenSQL("*")
		End Function

		Function CekDagilimiIsmeGore(ByVal Process As Token, ByVal Bolge As String, ByVal Harf As String) As Recordset
			Q("select a.hturu,a.kararno,a.kimlik,rtrim(b.adi)+' '+rtrim(b.soyadi) as adi,a.cekno,d.bolge")
			Q("from yaslılık..yasmaas a inner join yaslılık..yasmaasbil b on a.hturu = b.hturu and a.kararno = b.kararno and a.kimlik = b.kimlik and a.yil = 2009 and a.ay = 4")
			Q("inner join yaslılık..yoklama2008 c on a.hturu = c.hturu and a.kararno = c.kararno and a.kimlik = c.kimlik")
			Q("left join yaslılık..odemeyeri d on c.odeyerkod = d.odeyerkod")
			Q("where a.odeyerkod = 0")
			If Bolge <> "" Then Q("and d.bolge = '" & Bolge & "'")
			If Harf <> "" Then Q("and a.adi like '" & Harf & "%'")
			Q(" order by a.kimlik")
			Return Process.OpenSQL("*")
		End Function

		Function CekDagilimiKimligeGore(ByVal Process As Token, ByVal Bolge As String) As Recordset
			Q("select a.hturu,a.kararno,a.kimlik,rtrim(b.adi)+' '+rtrim(b.soyadi) as adi,a.cekno,d.bolge")
			Q("from yaslılık..yasmaas a inner join yaslılık..yasmaasbil b on a.hturu = b.hturu and a.kararno = b.kararno and a.kimlik = b.kimlik and a.yil = 2009 and a.ay = 4")
			Q("inner join yaslılık..yoklama2008 c on a.hturu = c.hturu and a.kararno = c.kararno and a.kimlik = c.kimlik")
			Q("left join yaslılık..odemeyeri d on c.odeyerkod = d.odeyerkod")
			Q("where a.odeyerkod = 0")
			If Bolge <> "" Then Q("and d.bolge = '" & Bolge & "'")
			Q(" order by a.kimlik")
			Return Process.OpenSQL("*")
		End Function

		Function DurumListesi(ByVal Token As Token, ByVal durum As String, ByVal bolge As String) As Recordset
			Q("select hturu,kararno,kimlik,rtrim(adi)+' '+rtrim(soyadi) as adi")
			Q("from yaslılık..yasmaasbil where yoklama = @durum and bolgekod = @bolge")
			Q("and odeyerkod < 900 and kimlik not in (select distinct kimlik from shesk where bordrotar >= @tarih)")
			Q("order by hturu,kararno,kimlik")
			Return Token.OpenSQL("*", durum, bolge, New Date(Today.Year - 1, 1, 1))
		End Function

		Sub IadeIsle(ByVal Token As Token, ByVal hturu As String, ByVal kararno As Integer, ByVal kimlik As String, ByVal telefon As String, ByVal adr As String, ByVal adrsemt As String, ByVal adrsehir As String)
			Token.BeginTran()
			Q("update yaslılık..yasmaasbil set yoklama = 'İ', telefon = @telefon, adr = @adr, adrsemt = @adrsemt, adrsehir = @adrsehir")
			Q("where hturu = @hturu and kararno = @kararno and kimlik = @kimlik")
			Token.ExecSQL("*", telefon, adr, adrsemt, adrsehir, hturu, kararno, kimlik)
			Token.CommitTran()
		End Sub

	End Module
End Namespace

